package internal_map_hash

import "unsafe"

type hasher[K comparable] struct {
	hash hashFn
	seed uintptr
}

func NewH[K comparable]() *hasher[K] {
	m := any(make(map[K]bool))
	mm := (*intfaceMap)(unsafe.Pointer(&m))
	h := mm.typ.hasher
	return &hasher[K]{
		hash: h,
		seed: newHashSeed(),
	}
}

func (h *hasher[K]) Sum(key K) uint64 {
	p := noescape(unsafe.Pointer(&key))
	return uint64(h.hash(p, h.seed))
}
